class Solution(object):
    def reverseStr(self, s, k):
        """
        :type s: str
        :type k: int
        :rtype: str
        """
        t = ''
        n = len(s)
        index = 0
        while index < n:
            if index + 2 * k < n:
                t += s[index: index + k][::-1]
                t += s[index + k: index + 2 * k]
                index += 2 * k
            else:
                if index + k <= n:
                    t += s[index: index + k][::-1]
                    t += s[index + k: n]
                    index = n
                else:
                    t += s[index: n][::-1]
                    index = n
        return t


data = Solution()
s = "abcdefg"
k = 2
print(data.reverseStr(s, k))
